#!/bin/bash

# 启动带有ROS环境的VSCode
# 使用方法: ./start_vscode.sh

echo "Setting up ROS environment..."

# Source ROS environment using env.sh
if [ -f "./env.sh" ]; then
    source ./env.sh
    echo "Sourced environment from env.sh"
else
    echo "Warning: env.sh not found, falling back to manual setup"
    # Fallback to manual setup
    source /opt/ros/humble/setup.bash
    export UNITREE_ROS2_DIR=~/unitree/unitree_ros2
    if [ -f "$UNITREE_ROS2_DIR/setup.sh" ]; then
        source $UNITREE_ROS2_DIR/setup.sh
        echo "Sourced unitree_ros2 environment from $UNITREE_ROS2_DIR"
    fi
    if [ -f "./install/setup.sh" ]; then
        source ./install/setup.sh
        echo "Sourced local workspace environment"
    fi
fi

echo "Environment variables set:"
echo "  UNITREE_ROS2_DIR: $UNITREE_ROS2_DIR"
echo "  AMENT_PREFIX_PATH: $AMENT_PREFIX_PATH"
echo "  CMAKE_PREFIX_PATH: $CMAKE_PREFIX_PATH"
echo "  LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
echo "  ROS_DISTRO: $ROS_DISTRO"
echo "  ROS_VERSION: $ROS_VERSION"

echo "Starting VSCode with ROS environment..."
code .